package com.ttxs.common.redis;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import java.time.Duration;

//@Service
@Slf4j
public class RedisService {
    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;

    public void set(String key, Object value) {
        redisTemplate.opsForValue().set(key, value);
    }

    public void set(String key, Object value, Duration expire) {
        redisTemplate.opsForValue().set(key, value, expire);
    }

    public void del(String key) {
        redisTemplate.delete(key);
    }

    public Object get(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    public boolean hasKey(String key) {
        Boolean found = redisTemplate.hasKey(key);
        if (log.isDebugEnabled()) {
            log.debug("hasKey: {}, {}", found, key);
        }
        return found.booleanValue();
    }
}
